# 导包
import time
from appium import webdriver
from appium.options.android import UiAutomator2Options
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.wait import WebDriverWait

# 配置移动端设备信息
des_caps = {
    "platformName": "Android",  # 移动端系统平台
    "platformVersion": "12",  # 平台对应版本
    "deviceName": "mumu",  # 设备名称（可以随便写）
    "appPackage": "com.netease.yanxuan",  # 包名
    "appActivity": ".SplashActivityDefault"  # Activity页面名
}
# 初始化设备配置信息
option = UiAutomator2Options().load_capabilities(des_caps)
# 创建驱动对象
driver = webdriver.Remote("http://127.0.0.1:4723/wd/hub", options=option)
time.sleep(1)
#app操作
#1.点击同意
WebDriverWait(driver, 10).until(
    EC.visibility_of_element_located((By.XPATH, "//*[@text='同意']"))).click()
#2.点击个人
ele = WebDriverWait(driver, 10).until(
    EC.visibility_of_element_located((By.XPATH, "//android.widget.TextView[@text='个人']")))
ele.click()
#3.切换登录方式
WebDriverWait(driver, 10).until(
    EC.visibility_of_element_located((By.XPATH, '(//android.widget.ImageView[@resource-id="com.netease.yanxuan:id/img_icon"])[2]'))).click()
WebDriverWait(driver, 10).until(
    EC.visibility_of_element_located((By.ID, "com.netease.yanxuan:id/newOtherLoginTypes"))).click()



#勾选协议
WebDriverWait(driver, 10).until(
    EC.visibility_of_element_located((By.XPATH, '//android.widget.CheckBox[@resource-id="com.netease.yanxuan:id/check_box"]'))
).click()
WebDriverWait(driver, 10).until(
    EC.visibility_of_element_located((By.XPATH, '(//android.widget.ImageView[@resource-id="com.netease.yanxuan:id/img_icon"])[4]'))).click()

#4.邮箱及密码登录
WebDriverWait(driver, 10).until(
    EC.visibility_of_element_located((By.ID, "com.netease.yanxuan:id/account_edit"))
).send_keys("15588556751@163.com")
WebDriverWait(driver, 10).until(
    EC.visibility_of_element_located((By.ID, "com.netease.yanxuan:id/password_edit"))
).send_keys("Wys20050404")
WebDriverWait(driver, 10).until(
    EC.visibility_of_element_located((By.ID, "com.netease.yanxuan:id/login_btn"))
).click()
# 暂停3秒

# 关闭驱动

